import ExamStatus from '@/components/type-of-exam/types/exam-status';
import { User } from '@/model/login/User';
import { QuestionaireQo } from '@/services/quest';
import { QuestionResult } from '@/store/answer/types';
// import { QuestionResult } from '@/store/answer/types';
import { ExamItem, Questionaire } from '../types';
import DetailListAdapter from './DetailListAdapter';

export default class QuestAdapter {
  parse(value: Questionaire, userId?: string): QuestionaireQo {
    const po: QuestionaireQo = {
      // startTime: dayjs()
      //   .add(1, 'day')
      //   .startOf('day')
      //   .format('YYYY-MM-DD HH:mm:ss'),
      // endTime: dayjs().add(1, 'day').endOf('day').format('YYYY-MM-DD HH:mm:ss'),
    };

    po.queTitle = value.queTitle;
    po.explanation = value.explanation;

    if (!userId) {
      po.createBy = (
        localStorage.getItem('userInfo') as unknown as User
      ).userId;
    } else {
      po.createBy = userId;
    }

    if (value.queId) {
      po.queId = value.queId;
    }
    if (value.queType) {
      // po.queType = value.queType;
    }

    return po;
  }

  compose(value: QuestionResult): Questionaire {
    const vo: Questionaire = {
      answerCount: value.answerCount,
      createBy: value.createBy,
      createTime: value.createTime,
      delFlag: value.delFlag,
      // vo.details = value.details;
      explanation: value.explanation,
      queId: value.queId,
      queTitle: value.queTitle,
      status: value.status,
      submissionTips: value.submissionTips,
      updateTime: value.updateTime,
      //
      queType: 1,
      startTime: value.startTime,
      endTime: value.endTime,
    };

    return vo;
  }

  composeDetails(value: QuestionResult, status: ExamStatus): ExamItem[] {
    const result = new DetailListAdapter().compose(value.details, status);
    return result;
  }
}
